package com.lanelu.hencoderplusstudy.view.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * 画心形
 */
public class Practice9DrawPathView extends View {

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public Practice9DrawPathView(Context context) {
        super(context);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Path path = new Path();
        path.addArc(200f, 200f, 400f, 400f, -225f, 225f);
        path.arcTo(400f, 200f, 600f, 400f, -180f, 225f, false);
        path.lineTo(400f, 542f);

        canvas.drawPath(path, paint);


//        练习内容：使用 canvas.drawPath() 方法画心形
    }
}
